package com.miplus.ccrm.workflow.controller;
import com.miplus.ccrm.common.CmdResVo;
import com.miplus.ccrm.common.PageData;
import com.miplus.ccrm.common.R;
import com.miplus.ccrm.workflow.model.dto.recycle.*;
import com.miplus.ccrm.workflow.model.vo.WorkflowRecycleVO;
import com.miplus.ccrm.workflow.service.WorkflowRecycleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
/**
 * 话术回收站Controller
 */
@Slf4j
@RestController
@RequestMapping("/api/workflow/recycle")
@RequiredArgsConstructor
@Api(tags = "话术回收站管理")
public class WorkflowRecycleController {

    private final WorkflowRecycleService workflowRecycleService;

    @PostMapping("/list")
    @ApiOperation("分页查询回收站话术")
    public R<PageData<WorkflowRecycleVO>> getRecyclePage(@RequestBody RecycleQueryDTO dto) {
        return R.SuccessPage(workflowRecycleService.getRecyclePage(dto));
    }

    @PostMapping("/restore")
    @ApiOperation("恢复话术")
    public R<CmdResVo> restoreWorkflow(@RequestBody RestoreWorkflowDTO dto,
                                       HttpServletRequest request) {
        String userId = getUserId(request);
        return R.Success(workflowRecycleService.restoreWorkflow(dto, userId));
    }

    @PostMapping("/permanent/delete")
    @ApiOperation("永久删除话术")
    public R<CmdResVo> permanentDelete(@Valid @RequestBody PermanentDeleteDTO dto,
                                       HttpServletRequest request) {
        String userId = getUserId(request);
        return R.Success(workflowRecycleService.permanentDelete(dto, userId));
    }

    @PostMapping("/clear")
    @ApiOperation("清空回收站")
    public R<CmdResVo> clearRecycle(@Valid @RequestBody ClearRecycleDTO dto,
                                    HttpServletRequest request) {
        String userId = getUserId(request);
        return R.Success(workflowRecycleService.clearRecycle(dto, userId));
    }
    /**
     * 从请求中获取用户ID
     */
    private String getUserId(HttpServletRequest request) {
        // 这里应该从token或session中获取用户ID
        // 暂时返回固定值，实际项目中需要根据具体的认证方式实现
        return "current_user_id";
    }
}